<?php

namespace App\Models;


use Dcat\Admin\Models\Administrator;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class WorkOrder extends Model
{
    use SoftDeletes;

    protected $table = 'work_orders';

    protected $dates = ['opening_at', 'pre_delivery_at', 'deleted_at'];

    protected $fillable = [
        'workshop_id',
        'brand_id',
        'user_id',
        'order_sn',
        'car_id',
        'car_number',
        'car_frame',
        'factory_year',
        'user_name',
        'user_phone',
        'user_email',
        'remarks',
        'opening_at',
        'pre_delivery_at',
        'maintenance_days',
        'service_advisor_id',
        'is_return',
        'is_urgent',
        'is_accident',
        'is_self_pay',
        'is_appointment',
        'is_pre_spray',
        'status',
        'settlement_at'
    ];

    public function brand()
    {
        return $this->belongsTo(Brand::class);
    }

    public function workshop()
    {
        return $this->belongsTo(Workshop::class);
    }

    public function user()
    {
        return $this->belongsTo(Administrator::class);
    }

    public function car()
    {
        return $this->belongsTo(Car::class);
    }

    public function serviceAdvisor()
    {
        return $this->belongsTo(Administrator::class, 'service_advisor_id');
    }

    public function component()
    {
        return $this->hasMany(WorkOrderComponent::class);
    }

    public function dispatch()
    {
        return $this->hasMany(WorkOrderDispatch::class);
    }
}
